﻿using System;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace Koonsoft.HYCRM.DAL
{
    public class FinancialAuditDAL
    {
        private Database database = DatabaseFactory.CreateDatabase("KOONCRMDB");

        /// <summary>
        /// 执行按单对账
        /// </summary>
        /// <param name="beginDate"></param>
        /// <param name="finishDate"></param>
        /// <param name="branchID"></param>
        public void AuditByOrders(string beginDate, string finishDate, int branchID)
        {
            const string procedure = "Payment_AuditByOrderID";

            using (var cmd = database.GetStoredProcCommand(procedure))
            {
                database.AddInParameter(cmd, "@begintime", DbType.DateTime, Convert.ToDateTime(beginDate));
                database.AddInParameter(cmd, "@finishtime", DbType.DateTime, Convert.ToDateTime(finishDate));
                database.AddInParameter(cmd, "@branchID", DbType.Int32, branchID);
                database.ExecuteNonQuery(cmd);
            }
        }

        /// <summary>
        /// 执行按月对账
        /// </summary>
        public void AuditByMonth()
        {
        }

        /// <summary>
        /// 查询某月对账信息
        /// </summary>
        /// <param name="year"></param>
        /// <param name="month"></param>
        /// <param name="branchID"></param>
        /// <returns></returns>
        public DataTable GetOrderAuditsByBranch(int year, int month, int branchID)
        {
            const string procedure = "Audit_GetOrderAuditByBranch";

            using (var cmd = database.GetStoredProcCommand(procedure))
            {
                database.AddInParameter(cmd, "@year", DbType.Int32, year);
                database.AddInParameter(cmd, "@month", DbType.Int32, month);
                database.AddInParameter(cmd, "@branchid", DbType.Int32, branchID);

                return database.ExecuteDataSet(cmd).Tables[0];
            }
        }
    }
}
